package cn.com.tuns.assess.qsb.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import cn.com.tuns.assess.qsb.R;
import cn.com.tuns.assess.qsb.frame.ui.BaseActivity;
import cn.com.tuns.assess.qsb.frame.ui.MyApplication;
import cn.com.tuns.assess.qsb.frame.util.SharedPreferencesUtil;
import cn.com.tuns.assess.qsb.frame.widget.DialogUtil;
import cn.com.tuns.assess.qsb.frame.widget.x5web.X5WebView;

public class TestAcivity extends BaseActivity {

    private X5WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setRequestPermissionListener(new RequestPermissionListener() {
            @Override
            public void onRequestPermissionListener(int requestCode, boolean granted) {
                MyApplication.context.init();
                init();
            }
        });
        if(!checkDangerousPermissions(permissions))
        {
            requestDangerousPermissions(permissions,104);
        }
        else {
            MyApplication.context.init();
            init();
        }




    }

    private void init(){
        Intent intent=new Intent(this,BrowserActivity.class);
        startActivity(intent);
        finish();
//        setContentView(R.layout.test_web_view);
//        webView=findViewById(R.id.webview);
//        webView.setWebChromeClient(new WebChromeClient(){
//            @Override
//            public boolean onJsAlert(WebView webView, String s, String s1, JsResult jsResult) {
//                return super.onJsAlert(webView, s, s1, jsResult);
//            }
//        });
//        webView.setWebViewClient(new WebViewClient(){
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//                //这里可以对特殊scheme进行拦截处理
//                return false;//要返回true否则内核会继续处理
//            }
//
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//                //这里可以对特殊scheme进行拦截处理
//                return false;//要返回true否则内核会继续处理
//            }
//        });
//        webView.loadUrl("https://debugtbs.qq.com/");
////        webView.loadUrl("http://soft.imtt.qq.com/browser/tes/feedback.html");
////        webView.loadUrl("http://www.baidu.com/");
//
//        if(AndroidUtils.isApkInDebug(this))
//        {
//            View view=findViewById(R.id.test);
//            view.setVisibility(View.VISIBLE);
//            view.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    showTestDialog();
//                }
//            });
//        }
    }


    private void showTestDialog(){
        String url= SharedPreferencesUtil.read(SharedPreferencesUtil.TestWebUrl);
        if(TextUtils.isEmpty(url))
        {
            url="http://192.168.2.58:8000/login";
        }

        View root=View.inflate(this,R.layout.test_dialog_main,null);
        final EditText editText=root.findViewById(R.id.weburl);
        editText.setText(url);
        View qd=root.findViewById(R.id.text_right);
        View cansel=root.findViewById(R.id.text_left);

        final DialogUtil dialogUtil = new DialogUtil(this, root, DialogUtil.Type.Center, true);
        qd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url=editText.getText().toString();
                SharedPreferencesUtil.save(SharedPreferencesUtil.TestWebUrl,url);
                dialogUtil.dismiss();

                webView.loadUrl(url);
            }
        });
        cansel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogUtil.dismiss();
            }
        });
        dialogUtil.show();

    }

    @Override
    public void onBackPressed() {
        if(webView.canGoBack())
        {
            webView.goBack();
        }
        else {
            super.onBackPressed();
        }

    }
}
